package com.lifeonwalden.copula;

import com.lifeonwalden.copula.bean.OptimizeBounds;
import com.lifeonwalden.copula.bean.OptimizeOptions;
import com.lifeonwalden.copula.bean.OptimizeResult;

import java.math.BigDecimal;
import java.util.Optional;
import java.util.function.Function;

public interface Estimation {
    /**
     * Computes the CMLE on a specified log-likelihood function.
     *
     * @param logLikelihood   The log-likelihood.
     * @param thetaStart      Initial value of theta in optimization algorithm.
     * @param bounds          Allowed values of theta.
     * @param optimizeOptions The optimization options used.
     * @return
     */
    static OptimizeResult cmle(Function<BigDecimal, BigDecimal> logLikelihood, BigDecimal thetaStart, Optional<OptimizeBounds> bounds, OptimizeOptions optimizeOptions) {
        if (optimizeOptions.isScalar()) {
            if (bounds.isPresent()) {
                switch (optimizeOptions.getMinimizeScalarMethod()) {
                    case BOUNDED: {
                        return Optimize.minimizeScalarBounded(logLikelihood, bounds.get(), BigDecimal.valueOf(1e-5), 200);
                    }
                    default: {
                        throw new RuntimeException("Not support yet.");
                    }
                }
            } else {
                throw new RuntimeException("Not support yet.");
            }
        } else {
            throw new RuntimeException("Not support yet.");
        }
    }
}
